package com.hzsun.rocketmq.spring.producer;

import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.messaging.Message;

/**
 * @Author: DingJl
 * @Date: 2022/1/22 16:03
 * @Version 1.0
 */
@RocketMQTransactionListener
public class TransactionListenerImpl  implements RocketMQLocalTransactionListener {
    @Override
    public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object o) {
        System.out.println("/**********************/");
        System.out.println("执行本地事务！");
        System.out.println(message.getClass());
        System.out.println("/**********************/");
        return RocketMQLocalTransactionState.COMMIT;
    }

    @Override
    public RocketMQLocalTransactionState checkLocalTransaction(Message message) {

        System.out.println("/**********************/");
        System.out.println("检查本地事务！");
        System.out.println("/**********************/");
        return RocketMQLocalTransactionState.ROLLBACK;
    }
}
